﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bookkeeping.Core.Entities;

namespace Bookkeeping.Web.UserControls
{
    public partial class PostListControl : System.Web.UI.UserControl
    {
        private string _title;

        public string Title
        {
            get
            {
                return Server.HtmlEncode(_title);
            }
            set
            {
                _title = value;
            }
        }

        public IEnumerable<Post> Posts { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            RefreshPostList();
        }

        public void RefreshPostList()
        {
            postRepeater.DataSource = Posts;
            postRepeater.DataBind();
        }

        protected void BindPost(Object Sender, RepeaterItemEventArgs e)
        {
            Post post = (Post)e.Item.DataItem;
            var postControl = (PostControl)e.Item.FindControl("postControl");

            postControl.IsAlternateRow = e.Item.ItemType == ListItemType.AlternatingItem;

            postControl.Post = post;
        }
    }
}